﻿using UnityEngine;
using System.Collections;
using DG.Tweening;

public class ImageView : MonoBehaviour
{
    public GROUP group;
    public Vector2 max_pos;                     //最大化坐标
    public Vector2 max_size = Vector2.one;      //最大化尺寸
    public Vector3 max_rotation;                //最大化旋转角度

    public Vector2 min_pos;                     //最小化坐标
    public Vector2 min_size = Vector2.zero;     //最小化尺寸
    public Vector3 min_rotation;                //最小化旋转角度

    public Transform images;                    //最大化父物体
    public Transform menus;                     //最小化父物体
    // Use this for initialization
    void Start()
    {
        EventManager<GROUP>.AddEvent(EventType.Maximize, OnMaximize);
        EventManager<GROUP>.AddEvent(EventType.Minimize, OnMinimize);
    }

    public void OnDestroy()
    {
        EventManager<GROUP>.RemoveEvent(EventType.Maximize);
        EventManager<GROUP>.RemoveEvent(EventType.Minimize);
    }
    public static Tweener t1, t2;
    public void OnMaximize(GROUP group)
    {
        if (group == this.group)
        {
            transform.parent = images;
            t1 = transform.DOLocalMove(max_pos, 1);
            transform.DOScale(max_size, 1);
            transform.DOLocalRotate(max_rotation, 1);
            GameManager.b_ismax = true;
            GameManager.group = group;
            GameManager.b_isani = true;
            t1.OnComplete<Tweener>(() => {
                transform.GetComponent<BoxCollider2D>().enabled = true;
                GameManager.b_isani = false;
            });
        }
    }

    public void OnMinimize(GROUP group)
    {
        if (group == GROUP.ALL || group == this.group)
        {
            transform.parent = menus;
            t2 = transform.DOLocalMove(min_pos, 1);
            GameManager.b_isani = true;
            t2.OnComplete<Tweener>(() =>
            {
                GameManager.b_isani = false;
            });
            transform.DOScale(min_size, 1);
            transform.DOLocalRotate(min_rotation, 1);
            GameManager.b_ismax = false;
            GameManager.group = GROUP.None;
            transform.GetComponent<BoxCollider2D>().enabled = false;
        }
    }

    public void Update()
    {

    }
}
